{include file="../application/admin/view/common/header.html" /}


<!--main content start-->
<section class="main-content">
    <!--start page content-->
    <div class="row">

        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="tabs">
                        <!-- Nav tabs -->
                        <ul class="list-inline tabs-nav" role="tablist">
                            <li role="presentation" class="active">
                                <a href="#copyright" aria-controls="copyright" role="tab" data-toggle="tab"
                                   aria-expanded="true">全部订单</a>
                            </li>
                            <li role="presentation" class="">
                                <a href="#trademark" aria-controls="trademark" role="tab" data-toggle="tab"
                                   aria-expanded="false">待付款</a>
                            </li>
                            <li role="presentation" class="">
                                <a href="#proprietary-technology" aria-controls="proprietary-technology" role="tab"
                                   data-toggle="tab" aria-expanded="false">待退款</a>
                            </li>
                            <li role="presentation" class="">
                                <a href="#patent" aria-controls="patent" role="tab" data-toggle="tab"
                                   aria-expanded="false">待打款</a>
                            </li>
                            <li role="presentation" class="">
                                <a href="#patent" aria-controls="patent" role="tab" data-toggle="tab"
                                   aria-expanded="false">已完成</a>
                            </li>
                            <li role="presentation" class="">
                                <a href="#patent" aria-controls="patent" role="tab" data-toggle="tab"
                                   aria-expanded="false">已失败</a>
                            </li>
							<li role="presentation" class="">
                                <a href="#patent" aria-controls="patent" role="tab" data-toggle="tab"
                                   aria-expanded="false">待确认</a>
                            </li>
                        </ul>
                        <input type="hidden" value="" id="select1">
                        <!-- Tab panes -->
                        <div class="tab-content">
                            <div role="tabpanel" class="tab-pane active" id="copyright">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="panel panel-default collapsed">
                                            <div class="panel-heading">

                                                <label style="color: #666666;font-size: 16px;font-weight: normal;line-height: 34px;margin: 3px 0;margin-right: 25px;">
                                                    交易方式:
                                                    <select id="select2"
                                                            style="height: 34px;border:1px solid #e0e0e0;width: 150px; ">
                                                        <option value="0">全部</option>
                                                    </select>
                                                </label>
                                                <div class="float-m" style="display: inline-block;">
                                                    <label>日期范围:</label>
                                                    <input type="text" id="logmin" class="input-text Wdate"
                                                           style="width:100px;display: inline-block;">
                                                    -
                                                    <input type="text" id="logmax" class="input-text Wdate"
                                                           style="width:100px;display: inline-block;">
                                                </div>

                                                <div class="search-form" style="margin-left:10px;width: 200px; ">
                                                    <input type="text" class="form-control" style="width: 200px;"
                                                           placeholder="输入订单编号/商品名称"/>
                                                    <button id="submit" type="button" class="btn-search"><i
                                                            class="fa fa-search"></i></button>
                                                </div>
                                            </div>
                                            <div class="panel-body">

                                                <table class="table table-hover table-striped table-bordered"
                                                       data-page-size="12" data-filter=#filter>
                                                    <thead>
                                                    <tr>
                                                        <th>选择</th>
                                                        <th>ID</th>
                                                        <th>订单编号</th>
                                                        <th>商品图片</th>
                                                        <th>商品名称</th>
                                                        <th>专利文件下载</th>
                                                        <th>买方</th>
                                                        <th>卖方</th>
                                                        <th>交易类型</th>
                                                        <th>实付款（¥）</th>
                                                        <th>创建时间</th>
                                                        <th>交易状态</th>
                                                        <th>操作</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>


                                                    </tbody>
                                                </table>
                                                <button class="btn" style="float: left;margin: 20px 0" onclick="down_excel()" title="下载">导出excel</button>
                                                <div class="pager" id="page" style="text-align: right;float: right;"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div><!--end row-->

    <!--end page content-->


</section>
<!--end main content-->


<!--Common plugins-->
<script src="_JS_/jquery.min.js"></script>
<script src="_JS_/jquery.base64.js"></script>
<script src="_JS_/jquery.cookie.js"></script>
<script src="_JS_/bootstrap.min.js"></script>
<script src="_JS_/jasny-bootstrap.min.js"></script>
<script src="_JS_/jquery.slimscroll.min.js"></script>
<script src="_JS_/jquery.nanoscroller.min.js"></script>
<script src="_JS_/metismenu.min.js"></script>
<script src="_JS_/float-custom.js"></script>
<script type="text/javascript" src="_JS_/layer/layer.js"></script>
<script type="text/javascript" src="_JS_/laypage/laypage.js"></script>
<script type="text/javascript" src="_JS_/laydata/laydate.js"></script>
<script type="text/javascript" src="_JS_/getMyDate.js"></script>
<!--<script src="_JS_/footable.all.min.js"></script>-->
<!-- Page-Level Scripts -->
<script>
    $(function () {
        postfile(1);
        getfile();
    });

    $("li a").click(function () {
        if ($(this).text() == '待付款') {
            $("#select1").val(1);
        } else if ($(this).text() == '待退款') {
            $("#select1").val(2);
        } else if ($(this).text() == '待打款') {
            $("#select1").val(3);
        } else if ($(this).text() == '已完成') {
            $("#select1").val(4);
        } else if ($(this).text() == '已失败') {
            $("#select1").val(5);
        } else if ($(this).text() == '待确认') {
            $("#select1").val(6);
        } else {
            $("#select1").val(0);
        }
        postfile(1);
    });

    function postfile(page) {
        var url = window.location.href;
        var static = $("#select1").val();
        var post;
        var show;
        if (url.split("?")[1] == "trading#" || url.split("?")[1] == "trading") {
            post = "trading";
			if (static == 1) {
                show = '1';
            } else if (static == 2) {
                show = '2';
            } else if (static == 3) {
                show = '3';
            } else if (static == 4) {
                show = '4';
            } else if (static == 5) {
                show = '5';
            } else if (static == 6) {
                show = '6';
            } else {
                show = '0';
            }
        } else if (url.split("?")[1] == "service#" || url.split("?")[1] == "service") {
            post = "service";
            if (static == 1) {
                show = '1';
            } else if (static == 2) {
                show = '2';
            } else if (static == 3) {
                show = '3';
            } else if (static == 4) {
                show = '4';
            } else if (static == 5) {
                show = '5';
            } else if (static == 6) {
                show = '6';
            } else {
                show = '0';
            }
        }
        var username = $('.search-form input').val();
        var logmin = $("#logmin").val();
        var logmax = $("#logmax").val();
        var transaction_id = $("#select2").val();
        $.ajax({
            type: 'GET',
            url: "{:url('api/orders/orders')}",
            dataType: 'jsonp',
            jsonp: 'callback',
            data: {
                'page': page,
                'static': show,
                'username': username,
                'logmin': logmin,
                'logmax': logmax,
                'transaction_id': transaction_id,
                'post': post
            },
            beforeSend: function () {
                var index = layer.load(1, {
                    shade: [0.1, '#333333'] //0.1透明度的白色背景
                });
            },
            success: function (msg) {
                layer.closeAll();
                $("#orders_management").addClass("active").children("ul").addClass("in");
                var url = window.location.href;
                if (url.split("?")[1] == "trading#" || url.split("?")[1] == "trading") {
                    $("#orders_trading").addClass("choose");
                    $("#page-title").html('交易宝贝管理');
                } else if (url.split("?")[1] == "service#" || url.split("?")[1] == "service") {
                    $("#orders_service").addClass("choose");
                    $("#page-title").html('服务宝贝管理');
                }
                if (msg.code == 200) {
                    var pages = Math.ceil(msg.data.count / 10);
                    $(".table tbody").html('');
                    if (msg.data.data.length > 0) {
                        for (var i = 0; i < msg.data.data.length; i++) {
                            var time = msg.data.data[i].time;
                            ltime = getMyDate(time * 1000);

                            var html = '<tr id="' + msg.data.data[i].id + '">';
                            html += '<td><input type="checkbox" name=""></td><td>' + msg.data.data[i].id + '</td>';
                            html += '<td>' + msg.data.data[i].order + '</td><td>';
                            if (post == "trading") {
                                html += '<img width="100px;" src="/Images/tradingMarket/' + msg.data.data[i].image + '"></td>';
                                html += '<td>' + msg.data.data[i].name + '</td>';
                                if (msg.data.data[i].contract) {
                                    html += '<td><a target="_blank" href="{:url('api/orders/download')}?id='+msg.data.data[i].id+'&type=2"  src="{:url('api/orders/download')}?id='+msg.data.data[i].id+'&type=2" class="download" style="cursor:pointer;">下载</a></td>';
                                } else {
                                    html += '<td>还未上传合同</td>';
                                }
                                html += '<td>' + msg.data.data[i].username + '</td>';
                                html += '<td>' + msg.data.data[i].seller + '</td><td>' + msg.data.data[i].transaction + '</td>';
                                if ((msg.data.data[i].status == 1 || msg.data.data[i].status == 10 || msg.data.data[i].status == 11 || msg.data.data[i].status == 12 || msg.data.data[i].status == 13) && msg.data.data[i].static == 1) {
                                    html += '<td class="money">0</td>';
                                } else {
                                    html += '<td class="money" id="' + msg.data.data[i].money + '">' + msg.data.data[i].money + '</td>';
                                }
                                html += '<td>' + ltime + '</td>';
                                if (msg.data.data[i].status == 1 && msg.data.data[i].static == 1) {
                                    html += '<td class="td-status enable">买家已报价，等待商家选择买家</td><td class="buttons td-manage">';
                                }  else if (msg.data.data[i].status == 2 && msg.data.data[i].static == 1) {
                                    html += '<td class="td-status disable">商家已选择买家，等待买家付款</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].status == 3 && msg.data.data[i].static == 1 && msg.data.data[i].index == 0) {
                                    html += '<td class="td-status disable">买家已付款，等待商家上传专利文件</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].status == 3 && msg.data.data[i].static == 1 && msg.data.data[i].index != 0) {
                                    html += '<td class="td-status disable">等待确认文件或商家再次上传专利文件</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].status == 4 && msg.data.data[i].static == 1) {
                                    html += '<td class="td-status disable">专利文件已上传，等待买家下载</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].statuc == 5 && msg.data.data[i].static == 1) {
                                    html += '<td class="td-status disable">买家文件下载成功,待确认文件</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].status == 5 && msg.data.data[i].static == 1) {
                                    html += '<td class="td-status disable">买家已确认，等待商家上传快递单号</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].status == 6 && msg.data.data[i].static == 1) {
                                    html += '<td class="td-status disable">商家已上传快递单号.等待买家确认收货</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].status == 7 && (msg.data.data[i].static == 4 || msg.data.data[i].static == 1)) {
                                    html += '<td class="td-status enable">买家已确认收货等待平台打款商家</td><td class="buttons td-manage">'+
									'<a class="btn btn-b table-btn" onclick="pay_money(this)" href="#" title="打款给商家">打款给商家</a>';
                                } else if (msg.data.data[i].status == 8 && (msg.data.data[i].static == 4 || msg.data.data[i].static == 1)) {
                                    html += '<td class="td-status pass">平台已打款商家，等待商家确认钱款</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].status == 9 && (msg.data.data[i].static == 4 || msg.data.data[i].static == 1)) {
                                    html += '<td class="td-status disable">商家已确认钱款，订单已完成</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].status == 10 && msg.data.data[i].static == 1) {
                                    html += '<td class="td-status disable">买家14个自然日内没有付款，订单取消</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].status == 11 && msg.data.data[i].static == 1) {
                                    html += '<td class="td-status disable">长时间未操作,订单取消</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].status == 12 && msg.data.data[i].static == 1) {
                                    html += '<td class="td-status disable">买家取消订单</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].status == 13 && msg.data.data[i].static == 3) {
                                    html += '<td class="td-status disable">退款成功，订单结束</td><td class="buttons td-manage">';
                                }else if (msg.data.data[i].static == 2) {
                                    html += '<td class="td-status disable">申诉成功，待退款</td><td class="buttons td-manage">'+
									'<a class="btn btn-b table-btn" onclick="refund_btn(this)" href="#" title="退款">退款</a>';
                                }
								
                            } else {
                                 html += '<img width="100px;" src="/Images/serviceGoods/' + msg.data.data[i].image + '"></td>';
                                html += '<td>' + msg.data.data[i].name + '</td>';
                                if (msg.data.data[i].contract) {
                                    html += '<td><a target="_blank" href="{:url('api/orders/download')}?id='+msg.data.data[i].id+'&type=2"  src="{:url('api/orders/download')}?id='+msg.data.data[i].id+'&type=2" class="download" style="cursor:pointer;">下载</a></td>';
                                } else {
                                    html += '<td>还未上传合同</td>';
                                }
                                html += '<td>' + msg.data.data[i].username + '</td>';
                                html += '<td>' + msg.data.data[i].seller + '</td><td>' + msg.data.data[i].transaction + '</td>';
                                if (msg.data.data[i].statuc == 1 || msg.data.data[i].statuc == 12) {
                                    html += '<td class="money">0</td>';
                                } else {
                                    html += '<td class="money" id="' + msg.data.data[i].money + '">' + msg.data.data[i].money + '</td>';
                                }
                                html += '<td>' + ltime + '</td>';


                                if (msg.data.data[i].statuc == 1) {
                                    html += '<td class="td-status enable">宝贝已拍下等待买家付款</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].statuc == 10 && msg.data.data[i].status == 12) {
                                    html += '<td class="td-status disable">协议不成功买家发起退款,商家未回复</td><td class="buttons td-manage">';
                                }else if (msg.data.data[i].statuc == 10 && msg.data.data[i].status == 13) {
                                    html += '<td class="td-status disable">商家同意退款</td><td class="buttons td-manage">' +
                                        '<a class="btn btn-b table-btn" onclick="refund_btn(this)" href="#" title="退款">退款</a>';
                                } else if (msg.data.data[i].static ==3 && msg.data.data[i].status == 8) {
                                    html += '<td class="td-status enable">双方确认收到合同</td><td class="buttons td-manage">' +
                                        '<a class="btn btn-b table-btn" onclick="pay_money(this)" href="#" title="打款给商家">打款给商家</a>';
                                } else if (msg.data.data[i].statuc == 6 && msg.data.data[i].status == 6) {
                                    html += '<td class="td-status enable">待审核并上传快递号</td><td class="buttons td-manage">';
                                    html += '<a class="btn btn-b table-btn" onclick="up_express(this)" href="#" title="确认审核上传快递号">确认审核上传快递号</a>';
                                } else if (msg.data.data[i].static == 4 ) {
                                    html += '<td class="td-status pass">交易完成</td><td class="buttons td-manage">';
                                } else if (msg.data.data[i].static == 5 ) {
                                    html += '<td class="td-status disable">交易失败</td><td class="buttons td-manage">';
                                } else {
                                    html += '<td class="td-status">' + msg.data.data[i].list_name + '</td><td class="buttons td-manage">';
                                }

                            }
                            html += '<a class="btn btn-c table-btn" onclick="orders_msg(this)" href="#" title="查看详情">查看详情</a></td></tr>';
                            $('.table tbody').append(html);
                        }
                    }
                    //分页
                    $(".table").attr("pages", page);
                    laypage({
                        cont: 'page',
                        pages: pages,
                        curr: page,
                        jump: function (obj, first) {
                            if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                postfile(obj.curr);
                            }
                        }
                    });
					
				

                } else {
                    layer.msg('获取信息不成功!', {icon: 5, time: 2000});
                }
            }
        })
    }

    function getfile() {
        var url = window.location.href;
        if (url.split("?")[1] == "trading#" || url.split("?")[1] == "trading") {
            var post = "trading"
        } else if (url.split("?")[1] == "service#" || url.split("?")[1] == "service") {
            var post = "service"
        }
        $.ajax({
            type: 'GET',
            url: "{:url('api/orders/get_orders')}",
            dataType: 'jsonp',
            data: {'post': post},
            jsonp: 'callback',
            success: function (msg) {
                if (msg.code == 200) {
                    if (msg.data.length > 0) {
                        for (var j = 0; j < msg.data.length; j++) {
                            if (post == 'trading') {
                                text = '<option value="' + msg.data[j].id + '">' + msg.data[j].trading_name + '</option>';
                            } else if (post == 'service') {
                                text = '<option value="' + msg.data[j].id + '">' + msg.data[j].t_name + '</option>';
                            }
                            $("#select2").append(text);
                        }
                    }
                }
            }
        })
    }


    // 搜索
    $('#submit').click(function () {
        postfile(1);
    })

    //回车键绑定搜索
    $(".search-form").keydown(function (event) {
        if (event.keyCode == 13) {
            postfile(1);
        }
    });

    // 交易方式
    $("#select2").change(function () {
        postfile(1);
    });

    //信息
    function orders_msg(obj) {
        var id = "#" + $(obj).parents('tr').attr('id');
        layer.open({
            type: 2,
            title: '订单信息',
            shadeClose: true,
            shade: 0.8,
            area: ['700px', '500px'],
            content: 'orders_msg.html' + id
        });
    }


    //退款
    function refund_btn(obj) {
        var page_id = "#" + $(".laypage_curr").html();
        var id = "#" + $(obj).parents('tr').attr('id');
        var refund = "#" + 'refund';
        layer.open({
            type: 2,
            title: '退款',
            shadeClose: true,
            shade: 0.8,
            area: ['350px', '250px'],
            content: 'orders_refund.html' + id + page_id + refund
        });
    }

    //打款给商家
    function pay_money(obj) {
        var id = "#" + $(obj).parents('tr').attr('id');
        var page_id = "#" + $(".laypage_curr").html();
        layer.open({
            type: 2,
            title: '提示',
            shadeClose: true,
            shade: 0.8,
            area: ['350px', '250px'],
            content: 'orders_refund.html' + id + page_id
        });
    }

    //上传快递单号
    function up_express(obj) {
        var id = "#" + $(obj).parents('tr').attr('id');
        var page_id = "#" + $(".laypage_curr").html();
        layer.open({
            type: 2,
            title: '提示',
            shadeClose: true,
            shade: 0.8,
            area: ['450px', '250px'],
            content: 'orders_express.html' + id + page_id
        });
    }


    //日期范围限制
    var start = {
        elem: '#logmin',
        format: 'YYYY-MM-DD',
        min: '1970-01-01', //设定最小日期为当前日期
        max: laydate.now(), //最大日期
        istime: false,
        istoday: false,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };

    var end = {
        elem: '#logmax',
        format: 'YYYY-MM-DD',
        min: '1970-01-01',
        max: laydate.now(),
        istime: false,
        istoday: false,
        choose: function (datas) {
            start.max = datas; //结束日选好后，充值开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);
	
	//导出excel
    function down_excel(){
        var url = window.location.href;
        if (url.split("?")[1] == "trading#" || url.split("?")[1] == "trading") {
             window.open("/index.php/api/form/get_excel?type=trading");
        } else if (url.split("?")[1] == "service#" || url.split("?")[1] == "service") {
             window.open("/index.php/api/form/get_excel?type=service");
        }
    };
</script>
</body>
</html>